import 'package:palmf_hid/common/utils/utils.dart';
import 'package:palmf_hid/common/values/conf.dart';

import 'common_order_util.dart';
//读取测试结果
List<Map<String, dynamic>> readTestResult(List<int> resultData,String mac) {
  // List<int> resultData=[0, 1, 68, 45, 68, 105, 109, 101, 114, 32, 32, 32, 2, 0, 0, 65, 76, 50, 51, 48, 53, 50, 55, 32, 32, 0, 136, 120, 93, 64];
  var res = intArrToHex(resultData).toUpperCase();
  MyLogUtil().i(res);
  List<Map<String, dynamic>> resultMap = [];
  int dataLen = (resultData.length) ~/ 30;
  for (int i = 0; i < dataLen; i++) {
    Map<String, dynamic> one = {};
    one["patientId"] = int.parse(res.substring(i * 60, i * 60 + 4), radix: 16);
    one["project"] = readProject(res.substring(i * 60 + 4, i * 60 + 24));
    one["saveNum"] = int.parse(res.substring(i * 60 + 24, i * 60 + 26));
    one["curveBatchNo"] = hexToAscii(res.substring(i * 60 + 30, i * 60 + 52))
        .replaceAll("\u0000", "")
        .trim();
    one["result"] =resultCal(resultData.sublist(i * 30+26, i * 30 + 30));
    one['mac'] = mac;
    one['hexString'] = res.substring(i * 60 + 52, i * 60 + 60);
    resultMap.add(one);
  }
  MyLogUtil().i(resultMap);
  return resultMap;
}


//结果值反转数组后计算单精度浮点数

double resultCal(List<int> data){
  return getFloatFromIntBits(intArrToHex(data.reversed.toList()));
}

//项目名称
String readProject(String data) {
  String result = hexToAscii(data
          .replaceAll(REF, TEMP_CHAR_REF)
          .replaceAll(BT, TEMP_CHAR_BT)
          .replaceAll(SYNC_BT, TEMP_CHAR_BT)
          .replaceAll(SYNC_REF, TEMP_CHAR_REF))
      .replaceAll(TEMP_CHAR_REF_CN, REF_STR)
      .replaceAll(TEMP_CHAR_BT_CN, BT_STR)
      .replaceAll('\u0000', "")
      .replaceAll(" ", "")
      .trim();
  // MyLogUtil().i('[$result]');
  return result;
}

//测试数据
var testData = [
  0,
  1,
  68,
  45,
  68,
  105,
  109,
  101,
  114,
  32,
  32,
  32,
  76,
  50,
  51,
  65,
  76,
  50,
  51,
  48,
  53,
  50,
  55,
  32,
  32,
  0,
  65,
  76,
  50,
  51
];
